Add ability to create test users with magic link logins - #2062
Conversation
|
@jbouquiaux could you test and review (probably more the backend part) this ? Likely we can add something in the dev-docker documentation with the command to add a user with the docker compose (something like "docker compose exec api-dev uv run invoke dev.create-test-user --username gloubs --role user") |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2062 +/- ##
==========================================
- Coverage 81.59% 81.57% -0.02%
==========================================
Files 88 88
Lines 8481 8489 +8
==========================================
+ Hits 6920 6925 +5
- Misses 1561 1564 +3
🚀 New features to boost your workflow:
|
ml-evs
left a comment
There was a problem hiding this comment.
Hi @davidwaroquiers, thanks for this. We definitely need something that solves this problem but I think I've come down against the idea of adding password-based login in this way.
I think my suggestion would be instead to hook into the email login approach and enable that by default on dev servers. We can then make invoke dev.serve provide an authenticated link with a token for testing the developers "normal" user by default, and an extra invoke task very similar to the one you added here that creates a test-user and prints a token link for the developer.
What do you think? Happy to implement this if you are okay with it, or go back to this idea if you still prefer a password.
Hi @ml-evs Thank you for the message. Just to mention that it is even not with a password it's "easier". Here is with a few screenshots: 1/ Login page:
2/ List of clickable passwordless users with some info (their role, the group(s) they belong to):
And you just click on the user you want to be logged in. That eases tests with different users with different roles, belonging to different groups, in the future it could also help test group admins, project admins etc ...). It is quite perpendicular to almost everything in datalab. It only touches four small points:
After a user is selected, everything follows the normal datalab "flow path" (using the Flask login session for access etc ...). What do you think ? |
fake email identity.
|
Ah sorry, I think I just searched for "password" and thought I was responding to #1898 🙃 I guess my question then becomes whether adding this to the UI itself is that useful, and if it really needs an API route? I'd prefer a task that lists these login users in the terminal and offers login links for each. Do you find the extra UI component that much more useful than having e.g., a few private browser windows logged in as different accounts? |
Not that much more useful indeed. I think the idea of having one invoke task that gives the list of passwordless users and their "properties" (roles, groups, ...) and the link is all good. I'll remove the UI part. As for the API route, we at least need the one to login no ? |
using an invoke task providing links.
|
Done, should be ready for review |
|
Could you take a look at 95aa6b0 @davidwaroquiers? I think this is the same functionality but without needing any extra config or routes, just lets you trigger token creation using your test accounts and prints the links you would use to login |
Hi @ml-evs Thanks! Works perfectly and indeed much better that there is no new route for that. My only "concern"/"question" is about the config option. Correct me if I'm wrong but we can create a test user for "any" deployment in this case. Just wondering if it wouldn't be better to keep the config option as a "gate" to prevent from creating test users in a "normal/production" deployment. When the test-user option is active (or when other security problems are there, e.g. secrets not matching or whatever), there could be a warning banner to inform the user that the deployment is not meant for production because of this or that. What do you think ? I'm fine either way if you think that is not needed (and anyway if we find out later that it would be useful, it can always be added later). Thanks! |
Great, I've added it to the end of this PR.
It's a fair point, it needs direct database access (at which point you could do a lot anyway). I've just tweaked this PR so it only creates the token links for emails on the It also goes back to only listing users with the .test domain (and renamed back to |
Perfect for me! Do you want me to make a final review ? |
If you have time -- just trying to tidy up merge/rebase! I'll also start work on the follow up PRs |
davidwaroquiers
left a comment
There was a problem hiding this comment.
All good to me, just one small comment about the tasks, to prevent them from running if TESTING is false maybe (see in the comment) ?
Had to go through #2121 to understand what it was doing because I thought that with TESTING true it would loose the purpose of test users (which is to test users roles, groups, access, ...).
ml-evs
left a comment
There was a problem hiding this comment.
Thanks for the review and initial PR @davidwaroquiers!
|
pre-commit.ci run |
|
pre-commit.ci autofix |


Added an additional login procedure for dev/tests. This is purposedly simplistic, just a username, and to login, you just click on the user in the list. The goal is to be able to test various access features / groups etc ... without the need to have multiple OAuth logins.
Adapted from the previous PR here: Matgenix#5
In this previous PR, a password credentials existed. Given the actual purpose of this, i.e. just be able to have different authenticated users easily in a purely test/dev environments, the password credentials added unnecessary code.
Logic in datalab for access to items/anything is:
1/ Authentication (who am I)
2/ Tenant access (do i have access to to this datalab instance)
3/ resource-level access control (can I access this specific "object")
This PR allow to kind of "bypass" 1/ and 2/ (not really bypass, just make it super easy for testing/development).
Adapted a bit from the above: now there are two invoke tasks that let you create test users and list them with login links that developers can use to test other accounts.
Closes #1898
Closes #2133